From b9e0af9b952cc300457d1d24838da82c1c474acd Mon Sep 17 00:00:00 2001 From: "cl349@firebug.cl.cam.ac.uk" Date: Wed, 7 Sep 2005 19:13:38 +0000 Subject: [PATCH] Don't leak memory when realloc fails. Signed-off-by: Christian Limpach --- tools/console/daemon/io.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c index 1bcdfdf04d..8f8f50ceee 100644 --- a/tools/console/daemon/io.c +++ b/tools/console/daemon/io.c @@ -279,6 +279,7 @@ static bool watch_domain(struct domain *dom, bool watch) static struct domain *create_domain(int domid) { struct domain *dom; + char *s; dom = (struct domain *)malloc(sizeof(struct domain)); if (dom == NULL) { @@ -306,10 +307,11 @@ static struct domain *create_domain(int domid) dom->conspath = xs_get_domain_path(xs, dom->domid); if (dom->conspath == NULL) goto out; - dom->conspath = realloc(dom->conspath, strlen(dom->conspath) + - strlen("/console") + 1); - if (dom->conspath == NULL) + s = realloc(dom->conspath, strlen(dom->conspath) + + strlen("/console") + 1); + if (s == NULL) goto out; + dom->conspath = s; strcat(dom->conspath, "/console"); if (!watch_domain(dom, true)) -- 2.30.2